package com.cykj.pos.util;

import com.alibaba.fastjson.JSONObject;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.pos.domain.dto.BizAgentidAppkeyDTO;
import com.cykj.pos.domain.dto.RiskControlDTO;

import java.util.HashMap;
import java.util.Map;

public class RiskControlUtil {

    public static AjaxResult getRiskControl(RiskControlDTO riskControlDTO, BizAgentidAppkeyDTO bizAgentidAppkeyDTO, String natchno, String token) throws Exception{
        System.out.println("--------------------------");
        System.out.println("--------------------------");
        System.out.println("---------风控接口：："+riskControlDTO+"-----------------");
        System.out.println("--------------------------");
        System.out.println("--------------------------");
        AjaxResult ajaxResult=AjaxResult.success("风控接口");
        //创建签约用户
        Map<String,Object> data=new HashMap<String,Object>();
        data.put("natchno",natchno);
        data.put("uid",bizAgentidAppkeyDTO.getUid());//账号中UID
        data.put("idcard",riskControlDTO.getIdcard());
        data.put("idtypename","1");
        data.put("inAcctName",riskControlDTO.getInAcctName());
        data.put("inAcctNo",riskControlDTO.getInAcctNo());
        data.put("ccyCode","OTHERBANK");
        data.put("cardType","DC");
        data.put("tranAmount",riskControlDTO.getTranAmount());
        data.put("cardAttribute","C");
        data.put("mobile",riskControlDTO.getMobile());
        String sign= SaasSignatureUtil.getSignature(bizAgentidAppkeyDTO);
        //业务参数（加密数据）
        String requestBody= AESUtil.encrypt(data,bizAgentidAppkeyDTO.getAppsecret());
        JSONObject getRiskControl=SaasSignatureUtil.submit(bizAgentidAppkeyDTO,"getRiskControl",sign,requestBody,token);
        if(getRiskControl.getString("code").equals("0000")){
            int pass=getRiskControl.getJSONObject("data").getInteger("pass");
            String description=getRiskControl.getJSONObject("data").getString("description");
            ajaxResult.put("code",getRiskControl.getString("code"));
            ajaxResult.put("message",getRiskControl.getString("message"));
            ajaxResult.put("pass",pass);
            ajaxResult.put("description",description);
            return ajaxResult;
        }else {
            ajaxResult.put("code","500");
            ajaxResult.put("message",getRiskControl.getString("message"));
            return ajaxResult;
        }
    }
}
